'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const {type} = event
	if(type==='upload'){
		const res = await db.collection('home').add({
			data:event.data
		})
		if(Object.keys(res).length>0){
			return {
				status:'S',
				message:'发布成功'
			}
		}
		return{
			status:'N',
			message:'发布失败，请稍后重试'
		}
	}else if(type==='getHome'){
		const res = await db.collection('home').get()
		if(res.data.length>0){
			return{
				status:'S',
				data:res.data,
				message:'加载成功'
			}
		}else{
			return{
				status:'N',
				data:[],
				message:'当前还没有数据'
			}
		}
	}
	//返回数据给客户端
	return event
};
